<?php
    require_once("BaseDataAdapter.php");
    class DirDataAdapter extends BaseDataAdapter {

        function Select() {
            if(!is_dir($this->dirname)) return '';
            
            $filesList = $this->_fileSystem->getFilesList($this->dirname,array('jpg','jpeg','bmp','png','gif'));
            $this->_XMLService->getXMLDataDOM($this->baseDir,$this->selectedDir,&$sItemName,&$sPhotoalbumDescription);
            
            $ItemFolder = new ItemFolder();
            $ItemFolder->description = $sPhotoalbumDescription;
            $ItemFolder->name = $sItemName;
            $ItemFolder->dirName = $this->selectedDir;
            $ItemFolder->ImageFileList = array();
            
            if($filesList!="")
            foreach( $filesList as $file)
            {
                $FileDataAdapter = new FileDataAdapter($this->selectedDir);
                array_push($ItemFolder->ImageFileList,$FileDataAdapter->Select($file));
            }
            
            return $ItemFolder;
        }
        
        function Update($DirObject,$OldDirname) {
            $this->_fileSystem->Dir_Rename($this->baseDir.$OldDirname,$this->baseDir.$DirObject->dirName);
            $this->_XMLService->UpdateXMLDataDOM($this->baseDir,$OldDirname,$DirObject->dirName,$DirObject->name,$DirObject->description);
        }
        
        function Insert($DirObject) {            
            $this->_fileSystem->Dir_Create($this->baseDir.$DirObject->dirName);
            $this->_XMLService->InsertXMLDataDOM($this->baseDir,$DirObject->dirName,$DirObject->name,$DirObject->description);
            $this->_XMLService->CreateXMLDataDOM($this->baseDir.$DirObject->dirName);
        }
        
        function Delete($item) {
            $this->_fileSystem->Dir_Delete($this->dirname);
            $this->_XMLService->DeleteXMLDataDOM($this->baseDir,$item);
        }
        
    }

?>
